package org.hxyjs.service.impl;

import org.hxyjs.dao.ActivitytypeDao;
import org.hxyjs.dto.DTO;
import org.hxyjs.dto.MessageEnum;
import org.hxyjs.entity.Activitytype;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.ActivitytypeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;

@Service("ActivitytypeService")
public class ActivitytypeServiceImpl implements ActivitytypeService {
    @Resource
    ActivitytypeDao activitytypeDao;
    @Override
    public DTO<Activitytype> getAllActivitytypes()  throws Exception{
        List<Activitytype> activitytypes = activitytypeDao.getAllActivitytypes();
        //isPresent表示判断不为空成立则dto为？与：之间的对象
        MessageEnum messageEnum  = Optional.ofNullable(activitytypes).isPresent()?MessageEnum.GETADMINSUCCESS:MessageEnum.GETADMINFAIL;
        return new DTO<Activitytype>(messageEnum.getCode(),messageEnum.getMessage(),activitytypes);
    }

    @Override
    public DTO<Activitytype> deleteActivitytypeByAtno(String atno)  throws Exception{
        Integer result = activitytypeDao.deleteActivitytypeByAtno(atno);
        //isPresent表示判断不为空成立则dto为？与：之间的对象
        MessageEnum messageEnum  =result> 0?MessageEnum.DELETEADMINSUCCESS:MessageEnum.DELETEADMINFAIL;
        return new DTO<Activitytype>(messageEnum.getCode(),messageEnum.getMessage());
    }
    @Override
    public DTO<Activitytype> getActivitytypeByAtno(String atno)  throws Exception{
        Activitytype activitytypes = activitytypeDao.getActivitytypeByAtno(atno);
        //isPresent表示判断不为空成立则dto为？与：之间的对象
        MessageEnum messageEnum  = Optional.ofNullable(activitytypes).isPresent()?MessageEnum.GETADMINSUCCESS:MessageEnum.GETADMINFAIL;
        return new DTO<Activitytype>(messageEnum.getCode(),messageEnum.getMessage());
    }

    @Override
    public DTO<Activitytype> getActivitytypeByPage(PageInfo pageInfo) throws Exception {

        List<Activitytype> activitytypes = activitytypeDao.getActivitytypeByPage(pageInfo);
        //isPresent表示判断不为空成立则dto为？与：之间的对象
        MessageEnum messageEnum  = Optional.ofNullable(activitytypes).isPresent()?MessageEnum.GETADMINSUCCESS:MessageEnum.GETADMINFAIL;
        return new DTO<Activitytype>(messageEnum.getCode(),messageEnum.getMessage(),activitytypes,pageInfo);
    }



    @Override
    public DTO<Activitytype> updateActivitytype(Activitytype activitytype) throws Exception {
        Integer result = activitytypeDao.updateActivitytype(activitytype);
        //isPresent表示判断不为空成立则dto为？与：之间的对象
        MessageEnum messageEnum  =result> 0?MessageEnum.UPDATEADMINSUCCESS:MessageEnum.UPDATEADMINFAIL;
        return new DTO<Activitytype>(messageEnum.getCode(),messageEnum.getMessage());
    }

    @Override
    public DTO<Activitytype> addActivitytype(Activitytype activitytype) throws Exception {
        Integer result = activitytypeDao.addActivitytypeByAno(activitytype);
        //isPresent表示判断不为空成立则dto为？与：之间的对象
        MessageEnum messageEnum  =result> 0?MessageEnum.ADDADMINSUCCESS:MessageEnum.ADDADMINFAIL;
        return new DTO<Activitytype>(messageEnum.getCode(),messageEnum.getMessage());
    }

    /**
     * 学生选课成功 学生成绩加1分，从选课信息中可以获得学生的学号就能查询出学生原来的成绩
     * @param sc
     * @return
     * @throws Exception
     */

}
